home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip / MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf / Programming / PASCAL_TUTES / tute1.pas < prev    next >
Pascal/Delphi Source File  |  1994-06-24  |  7KB  |  146 lines

  1.  
  2. {
  3.                                 Tutorial One
  4.  
  5.                 Write Lines?  I thought that was a school thing...
  6.  
  7.         Don't adjust your monitor!  The curly brackets indicate comments
  8.         for pascal programs.  In other words, this whole article is source
  9.         code that you can compile into an executable program.  It saves
  10.         on the re-typing and means no separate source files!  All the
  11.         extraneous remarks will be in these curly brackets and in this
  12.         colour (i.e. the guts of the tutorial), while the program lines
  13.         themselves will be coloured like this...
  14.  
  15.         This could be a program line but it isn't;
  16.  
  17.     You'll note that all curly brackets are part of the program. 
  18.     That's because they're all comments!
  19.  
  20.         If this isn't clear then go and have a cup of coffee, dip your
  21.         head in a bucket of sour milk, say "I love pickled herring" three
  22.         times, then come back and try again!
  23.  
  24.     Alternatively, run the program RemCom (found in the
  25.     example_programs drawer) which will remove all these comments from
  26.     the file, just leaving the source code.  Magic!
  27.  
  28.         What's more important?  Careful study of a subject until
  29.         understanding brings the confidence to apply your knowledge, or
  30.         suck it and see, the time-honoured approach to computer technology?
  31.         We'll use mostly the latter as we travel down the Pascal highway
  32.         towards enlightenment.  It's cruel and dirty, and produces
  33.         programming cowboys, but it's less likely to lead to early baldness
  34.         and debilitating halitosis.
  35.  
  36.         I know you're bursting to write your first Pascal program, so we'll
  37.         commence with a simple example program.  If you want to re-write
  38.         just the program lines you'll need a text editor, or word processor
  39.         capable of saving in ASCII format.  Also, a Pascal compiler would
  40.         be handy!  If you don't have the compiler I've included the
  41.         executables along with these tutorials in a drawer marked
  42.         "Example_Programs".  You'll need to open a CLI window to run them.
  43.  
  44.         Here is our first program... }
  45.  
  46.         Program MDTute1 (output);
  47.  
  48. {       ^       ^       ^       ^
  49.         |       |       |       |
  50.         |       |       |       |__     Semicolon: The end of every line
  51.         |       |       |               in a Pascal program is identified
  52.         |       |       |               by a semicolon.  Amazing.
  53.         |       |       |
  54.         |       |       |__     Output: Tell the compiler that we will be
  55.         |       |               requiring output from this program.  Note
  56.         |       |               the round brackets!
  57.         |       |
  58.         |       |__     Identifier: This is the name of our program.  It
  59.         |               must begin with a letter, then it may have any
  60.         |               number of digits or letters.  Try U682Higgle!
  61.         |
  62.         |__     Program: This tells your compiler that the textfile being
  63.                 examined is in fact a program.  The first word of every
  64.                 Pascal source file is Program.  This is a reserved word in
  65.                 Pascal, so you can't use it as a variable name or for
  66.                 scraping off the black bits from your burnt toast. }
  67.  
  68.         {       A brilliant program to output a message to the screen
  69.  
  70.                 Author : A N Peck
  71.  
  72.                 Date : 15 June 1994 }
  73.  
  74. {       This is a program comment.  While it's not necessary to write
  75.         anything, it is good programming practice to write here details of
  76.         the program's function, author and date of inception.  Even more
  77.         useful information can be kept here in an opening comment, and
  78.         we'll discuss that when we get into functions and procedures
  79.         (Yikes). }
  80.  
  81.         Begin
  82.  
  83. {       Begin: This is a really tricky concept.  It means that this is the
  84.         start of the program... }
  85.  
  86.         Writeln ('It''s a long way from Tipperary!');
  87.  
  88. {       ^       ^^   ^                            ^^
  89.         |       ||   |                            ||
  90.         |       ||   |                            ||__  Closing Bracket!
  91.         |       ||   |                            |
  92.         |       ||   |                            |__   Closing apostrophe
  93.         |       ||   |                            
  94.         |       ||   |__   I did mean to write this second apostrophe!
  95.         |       ||         Honest!  Actually because the writeln statement
  96.         |       ||         requires apostrophes, whenever we need a real
  97.         |       ||         one, we need to write it twice.  Cosmic.
  98.         |       ||      
  99.         |       ||__    Opening apostrophe              
  100.         |       |       
  101.         |       |__     Opening bracket 
  102.         |
  103.         |__     This weird word is another reserved word, and it tells the
  104.                 compiler that we want to output something (usually to the
  105.                 screen).  The Writeln command differs from Write in that
  106.                 writeln, after writing the statement in the brackets, will
  107.                 then enter a carriage return so that the next line will be
  108.                 on the next line (eh?)
  109.  
  110.               Example:  Writeln('Four stores and ');
  111.                         Writeln('seven shops ago...');
  112.  
  113.                                 produces the output
  114.  
  115.                         Four stores and 
  116.                         seven shops ago....
  117.  
  118.                                 whereas
  119.  
  120.                         Write('Four stores and ');
  121.                         Writeln('seven shops ago...');
  122.  
  123.                                 produces the output
  124.  
  125.                         Four stores and seven shops ago.... }
  126.  
  127.         Writeln;
  128.  
  129. {    ^
  130.     |
  131.     |__    This makes a blank line!  }
  132.  
  133.         End.
  134.  
  135. {       Another brutally torturous concept.  This is the end of the
  136.         program.  Note the fullstop! 
  137.  
  138.     Wasn't that exciting!  Before going on to the next tutorial,
  139.     why not play around with this code to produce your own program? 
  140.     Try centering the text, and writing multiple and blank lines. 
  141.     We'll talk of this text formatting again.  
  142.  
  143.     ----------------------END OF TUTE1.PAS---------------------- }
  144.  
  145.  
  146.